<template>
<h1>员工列表综合练习</h1>
  <el-form style="width: 600px; margin: 0 auto;" label-width="80">
    <el-form-item label="姓名">
      <el-input v-model="emp.name" placeholder="请输入姓名" ></el-input>
    </el-form-item>
    <el-form-item label="工资">
      <el-input v-model="emp.salary" placeholder="请输入工资" ></el-input>
    </el-form-item>
    <el-form-item label="岗位">
      <el-input v-model="emp.job" placeholder="请输入岗位" ></el-input>
    </el-form-item>
    <el-form-item >
      <el-button type="success" @click="add">点我提交</el-button>
    </el-form-item>
  </el-form>
    <br>
    <el-table  style="width: 600px; margin: 0 auto; " :data="p" >
      <el-table-column  type="index" label="编号" width="80"  align="center"></el-table-column>
      <el-table-column  prop="name" label="姓名" align="center"  ></el-table-column>
      <el-table-column  prop="salary" label="工资" align="center" ></el-table-column>
      <el-table-column  prop="job" label="岗位"  align="center" ></el-table-column>
      <el-table-column  label="操作" >
        <template #default="scope">
          <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
        </template>
      </el-table-column>


    </el-table>


</template>

<script setup>

import {ref} from "vue";

const emp = ref(
  {name:'',salary:'',job:''}
) ;
const p = ref([]);
const add = () =>{
  if (!emp.value.name || !emp.value.name.trim()
  ||!emp.value.salary || !emp.value.salary.trim()
  ||!emp.value.job || !emp.value.job.trim()
  ){
    alert('请输入员工的完整信息');
    return;
  }
  p.value.push(emp.value);
  emp.value={name:'',salary: '',job: ''}
  console.log(emp.value)
  }

const del = (index,emp)=> {
  if (confirm('您确定删除' + emp.name + '吗？')) {
    p.value.splice(index, 1);
  }
}
</script>

<style scoped>

</style>